<script setup>
import { artGetChannelService } from '@/api/article'
import { Edit, Delete } from '@element-plus/icons-vue'
import ChannelEdit from './components/ChannelEdit.vue'
import { artDeleteChannelService } from '@/api/article'
import { ref } from 'vue'
const channelList = ref([])
const loading = ref(false)
const getchannelList = async () => {
  loading.value = true
  const res = await artGetChannelService()
  channelList.value = res.data.data
  loading.value = false
}
getchannelList()
const dialog = ref()
const addDialog = () => {
  dialog.value.open()
}
const editDialog = (row) => {
  dialog.value.open(row)
}
const getSuccess = () => {
  getchannelList()
}
const artDelete = async (row) => {
  console.log(row)
  await ElMessageBox.confirm('你确认删除该分类信息吗？', '温馨提示', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    await artDeleteChannelService(row.id)
    ElMessage({
      type: 'success',
      message: '删除成功'
    })
  })
  getchannelList()
}
</script>

<template>
  <PageContainer title="文章分类">
    <template #extra>
      <el-button type="primary" @click="addDialog">添加分类</el-button>
    </template>

    <el-table v-loading="loading" :data="channelList" style="width: 100%">
      <el-table-column type="index" label="序号" width="100" />
      <el-table-column prop="cate_name" label="分类名称" />
      <el-table-column prop="cate_alias" label="分类别名" />
      <el-table-column label="操作" width="100">
        <template #default="{ row }">
          <el-button
            @click="editDialog(row)"
            plain
            circle
            type="primary"
            :icon="Edit"
          ></el-button>
          <el-button
            plain
            circle
            type="danger"
            :icon="Delete"
            @click="artDelete(row)"
          ></el-button>
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>
    <ChannelEdit ref="dialog" @success="getSuccess"></ChannelEdit>
  </PageContainer>
</template>
<style></style>
